package components;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import stdp_rules.STDP_Rule;

/**
 * An underused class, now used mainly for dealing with the annoyances of Java
 * generics. It's basically just a list where the generic type can only be 
 * something that extends AbstractNeuron.
 * @author zach
 *
 */
public class Layer <T extends AbstractNeuron> {

//	private T t;
//	private int numNeurons;
	private List<T> neurons;
	
	
	public Layer () {
		neurons = new ArrayList<T>();
	}
	
	public List<T> getNeuronList(){
		return neurons;
	}
	
	public T[] getNeuronArray(T [] arr){
		return neurons.toArray(arr);
	}
	
	public AbstractNeuron [] getAbstractArray(){
		return neurons.toArray(new AbstractNeuron[size()]);
	}
	
	public void setNeurons(T []  arr) {
		neurons = Arrays.asList(arr);
	}
	
	public T get(int index) {
		return neurons.get(index);
	}
	
	public int size(){
		return neurons.size();
	}
	
	public void setReporters(boolean reporter) {
		for(T n : neurons) {
			n.setReporter(reporter);
		}
	}
	
	public void setSTDP_Rule(STDP_Rule stdp) {
		for(T n : neurons) {
			n.setStdp(stdp);
		}
	}
	
	public void setStdpOn(boolean on) {
		for(T n : neurons) {
			n.setStdpOn(on);
		}
	}
	
	public void resetTime() {
		for(T n : neurons) {
			n.setTime(0);
			n.setLastSpike(0);
		}
	}
	
}
